package xyz.xuminghai.javafx_learn.scene.control;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Pagination;
import javafx.scene.layout.BorderPane;
import javafx.scene.shape.*;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.List;

/**
 * 2023/5/18 16:55 星期四<br/>
 * 分页控件
 *
 * @author xuMingHai
 */
public class PaginationApp extends Application {

    private final BorderPane borderPane = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {
        List<Shape> shapeList = new ArrayList<>();
        shapeList.add(new Text("一个文本节点"));
        shapeList.add(new Line(0.0, 0.0, 15.0, 0.0));
        shapeList.add(new CubicCurve(0.0, 0.0, 3.5, 7.5,
                14.5, 18.0, 44.5, 23.5));
        shapeList.add(new Ellipse(30.0, 50.0));
        shapeList.add(new Rectangle(30.0, 20.0));
        shapeList.add(new Arc(50.0, 50.0, 50.0, 50.0,
                0.0, 100.0));
        shapeList.add(new Circle(50.0));
        shapeList.add(new Polyline(14.0, 25.0, 34.0, 22.0));
        shapeList.add(new QuadCurve(0.0, 0.0, 18.0, 14.0,
                28.0, 34.0));


        Pagination pagination = new Pagination(shapeList.size());
        pagination.setPageFactory(shapeList::get);

        borderPane.setCenter(pagination);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(borderPane, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
